<?php

use yii\helpers\Html;
use mdm\admin\components\Helper;
use common\components\TGridView;
use yii\helpers\Url;
use yii\bootstrap\ActiveForm;
use common\helpers\TStringHelper;

/* @var $this yii\web\View */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = Yii::t('common', 'user_company');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="user-company-index">
    <?php echo $this->render('_search', ['params' => $params]); ?>
    <?php
    $gridColumns = [
        [
            'name' => 'selectedIds',
            'class' => 'kartik\grid\CheckboxColumn',
            'checkboxOptions' => function($model, $key, $index, $column) {
                return [
                    'value' => $model->id,
                ];
            }
        ],
        [
            'class' => 'kartik\grid\SerialColumn',
            'header' => Yii::t('common','serial_number'),
        ],
        [
            'attribute' => 'name',
            'header' => Yii::t('common', 'company_name'),
        ],
        [
            'header' => Yii::t('common', 'type'),
            'value' => function($model){
                return \common\helpers\TStringHelper::getCompanyType($model->type);
            }
        ],
        [
            'attribute' => 'telphone',
            'header' => Yii::t('common', 'company_telphone'),
        ],
        [
            'attribute' => 'contact_user',
            'header' => Yii::t('common', 'contact_user'),
        ],
        [
            'attribute' => 'contact_mobile',
            'header' => Yii::t('common', 'contact_mobile'),
        ],
        [
            'header' => Yii::t('common', 'status'),
            'value' => function($model){
                return \common\helpers\TStringHelper::getCompanyStatusText($model->status);
            }
        ],
        [
            'header' => Yii::t('common', 'created_at'),
            'value' => function($model){
                return \common\helpers\TStringHelper::ShowDate($model->created_at, 1);
            }
        ],
        [
            'header' => Yii::t('common', 'updated_at'),
            'value' => function($model){
                return \common\helpers\TStringHelper::ShowDate($model->updated_at, 1);
            }
        ],
        [
            'class' => 'kartik\grid\ActionColumn',
            'header' => Yii::t('common', 'operation_button'),
            'template' => '{view}{updatepop}{deleteButton}',
            'width' => '150px',
            'buttons' => [
                'updatepop' => function ($url, $model, $key) {
                    return TStringHelper::canBeModified($model->created_by) ? Html::a('<span class="glyphicon glyphicon-pencil"></span>', Yii::$app->urlManager->createUrl(['user-company/update', 'id' => $model->id]), ['class' => 'EditButton', 'title' => Yii::t('common', 'edit_button')]) : '';

                },
                'deleteButton' => function ($url, $model, $key) {
                    return TStringHelper::canBeModified($model->created_by) ? Html::a('<span class="glyphicon glyphicon-trash"></span>', '#', ['class' => 'DeleteButton', 'title' => Yii::t('common', 'delete_button'), 'onclick' => 'showDeleteModal("' . $key . '","' . Yii::$app->urlManager->createUrl(['banner/delete', 'id' => $model->id]) . '");']) : '';
                },
            ],
        ]
    ];

    $contentName = Yii::t('common', 'user_company');

    $addbtn = '';
    /*if(Helper::checkRoute('create')) {
        $addbtn = Html::a(Yii::t('common', 'create_{modelClass}', ['modelClass' => Yii::t('common', 'user_company'),]), ['create'], ['class' => 'btn btn-default greenBtn']);
    }*/

    $form = ActiveForm::begin([
        'id' => 'list-form'
    ]);

    echo TGridView::widget([
        'id'=>'grid',
        'dataProvider' => $dataProvider,
        //'filterModel' => $searchModel,
        'columns' => $gridColumns,
        'panel' => [
            'type' => TGridView::TYPE_DEFAULT,
            'heading' => '<h3 class="panel-title" style="text-align: left;"><i class="glyphicon glyphicon-book"></i> ' .Yii::t('common', '{value}_record', ['value'=>$contentName]).'</h3>',
        ],
        'toolbar' => [
            ['content'=>
                $addbtn
                /*.' '.
                (TStringHelper::canBeModified() ? Html::button('<i class="glyphicon glyphicon-refresh"></i> '.Yii::t('common', 'batch_update_button'),['title'=>Yii::t('common', 'batch_update_button'), 'class'=>'btn btn-default blueBtn', 'onclick' => 'batchUpdateOrderBtn("'.Yii::$app->urlManager->createUrl(['banner/batch-update-order']).'", "list-form")']) : '')*/
                .' '.
                (TStringHelper::canBeModified() ? Html::button('<i class="glyphicon glyphicon-minus"></i> '.Yii::t('common', 'batch_delete_button'),['title'=>Yii::t('common', 'batch_delete_button'), 'class'=>'btn btn-default redBtn', 'onclick' => 'batchDeleteBtn("'.Yii::$app->urlManager->createUrl(['banner/batch-delete']).'")']) : ''),
            ],
//            '{export}',
//            '{toggleData}'
        ],
        'pjax'=> false,
        'pjaxSettings'=>[
            'neverTimeout'=>true,
        ]
    ]);

    ActiveForm::end();
    ?>
    <div class="text-left">
        <?php
        echo \yii\widgets\LinkPager::widget([
            'id' => 'banner_page',
            'pagination'=>$dataProvider->pagination,
        ]);
        ?>
    </div>
</div>

<script>
    function loadList() {
        location.reload();
    }
</script>
